BOLD="\e[1m"        # 字体加粗
YELLOW="\e[33m"     # 黄色字体 
GREEN="\e[32m"      #绿色字体 
RESET="\e[0m"       # 关闭样式


info_print()
{
  echo -e "\e[1;33m[Build]:\e[0m \e[1;32m $1 \e[0m" 
}


rebuild()
{
  if [ -d "./build" ]; then
    echo "build已创建"
    else
    echo "创建文件夹:build"
    mkdir build
    fi


    cd build
    make clean

    info_print "cd build fold"
    info_print "start to cmake..."

    cmake ..
    info_print "cmake done..."

    info_print "ready to make"

    make
    info_print "make is finished"


    cd ..
    cd bin
    info_print "emulation  runing......"

    ./emulation

}


build()
{
  if [ -d "./build" ]; then
    echo "build已创建"
    else
    echo "创建文件夹:build"
    mkdir build
    fi
    cd build
    info_print "cd build fold"

    info_print "start to cmake..."
    cmake ..
    info_print "cmake done..."

   # 删除之前生成的执行文件
    cd ..
    cd bin
     rm emulation
    
    # 进入build文件夹，生成新的执行文件
    cd ..
    cd build
    info_print "ready to make"
    make
    info_print "make is finished"

    # 进入 bin文件夹，执行新生成的文件
    cd ..
    cd bin
    info_print "emulation  runing......"

    ./emulation

}





# 获取传递的参数
arg1="$1"
arg2="$2"

 info_print "run.sh version: 2025-3-13"
# # 根据参数进行判断和执行
if [ "$arg1" == "rebuild" ]; then
  rebuild

# elif [ "$arg1" == "option2" ]; then
#   # 执行操作2
#   echo "You chose option2"
else
  build
fi

# if [ "$arg1" == "rebuild"]; then

#     if [ -d "./build" ]; then
#     echo "build已创建"
#     else
#     echo "创建文件夹:build"
#     mkdir build
#     fi


#     cd build
#     make clean

#     info_print "cd build fold"
#     info_print "start to cmake..."

#     cmake ..
#     info_print "cmake done..."

#     info_print "ready to make"

#     make
#     info_print "make is finished"


#     cd ..
#     cd bin
#     info_print "emulation  runing......"

#     ./emulation
#   fi







